<?php
class ContactController extends AppController{
    public function index()
    {
        $lang_code = $this->Session->read('lang_code');
        $this->loadModel('Article'); $this->Article->lang_code = $lang_code;
        $contacts = $this->Article->get_article_by_category_id(104, 0, 1);
        $this->set('contacts', $contacts[0]);
        $breadcrumbs[] = array('title' => 'Liên hệ', 'link' => 'lien-he');
        $this->set('breadcrumbs', $breadcrumbs);
        
        $this->loadModel('Category'); $this->Category->lang_code = $lang_code;
        $parent_id = $this->Category->get_category_id_by_code('lien_he');
        $parent_info = $this->Category->get_info_category_by_id($parent_id);
        $meta_title = $parent_info['category_desc']['meta_title'];
        $meta_keywords = $parent_info['category_desc']['meta_keywords'];
        $meta_description = $parent_info['category_desc']['meta_description'];
        $this->set('meta_title', $meta_title); $this->set('meta_keywords', $meta_keywords); $this->set('meta_description', $meta_description);
        
        $send_status = '';
        if ($this->request->is('post')) {
            $name = @$this->request->data['name'];
            $address = @$this->request->data['address'];
            $phone = @$this->request->data['phone'];
            $email = @$this->request->data['email'];
            $subject = @$this->request->data['subject'];
            $message = @$this->request->data['message'];
            
            $content = "<strong>Name: </strong>".$name.'<br/>';
            $content.= "<strong>Phone: </strong>".$address.'<br/>';
            $content.= "<strong>Email: </strong>".$phone.'<br/>';
            $content.= "<strong>Address: </strong>".$email.'<br/>';
            $content.= "<strong>Subject: </strong>".$subject.'<br/>';
            $content.= "<strong>Message: </strong>".$message.'<br/>';
            
            $this->loadModel('Setting'); $this->Setting->lang_code = $lang_code;
            $settings = $this->Setting->get_setting();
            
            $Email = new CakeEmail();
            $Email->config('smtp');
            $Email->emailFormat('html');
            $Email->to(@$settings['email_send_request']);
            $Email->subject('Bạn có yêu cầu liên hệ');
            if ($Email->send($content) )
        	{
        		$send_status = "Gửi liên hệ thành công.";
        	}else{
        		$send_status = "Gửi liên hệ không thành công.";
        	}
        }
        
        $this->set('send_status', $send_status);
        
        
        $has_html = '';
        $this->set('has_html', $has_html);
        $header_menu_sidebar['title'] = $parent_info['category_desc']['title'];
        $header_menu_sidebar['link'] = 'lien-he';
        $this->set('header_menu_sidebar', $header_menu_sidebar);
        
        $menu_sidebar = array();
        $this->set('menu_sidebar', $menu_sidebar);
    }

}